<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Facades\Redis;

/*
 * 待作废，不允许继续新增业务
 * */
class UserTickets extends Model
{

    protected $table = 'user_tickets';
    public $timestamps = false;
    protected $primaryKey = 'id';

    /*
     * 获取ticket 信息
     * */
    public static function getRowsArr($where)
    {
        $expires_in = rand(3600, 7200);
        $key = 'user:ticket:'.md5(http_build_query($where));
        if(empty($rows = Redis::get($key))) {
            $rows = self::where($where)->first();
            if (empty($rows))
                return [];
            Redis::setex($key, $expires_in, $rows);
            return $rows->toArray();
        }
        return json_decode($rows, true);
    }

}
